<?php
/** Zend_Controller_Action */ 
require_once APPLICATION_PATH . '/../library/Soooner/Controller/Action.php';
require_once APPLICATION_PATH . '/../library/Common/Classes/Babel.php';
class CompoundController extends Soooner_Controller_Action
{
	private $_id;
	private $_modelCompound;
	private $_modelProject;
	//private $_modelSpectrumtype;
	private $_modelDictionaryitems;
	private $_modelCompoundspectrum;
	private $_modelCompoundsreference;
	private $_modelCompoundsave;
	private $_modelCompoundsalt;
	private $_modelCompoundsolvent;
	private $_modelCompoundgain;
	private $_mdelSalt;
	private $_modelStatus;
	private $_modelCompoundjson;
    public function init()
    {
        /* Initialize action controller here */
    	$this->initDzTemplate();
    	$this->_modelCompound = new Model_Tables_Compound();
    	$this->_modelProject = new Model_Tables_Project();
    	$this->_modelCompoundspectrum = new Model_Tables_Compoundspectrum();
    	//$this->_modelSpectrumtype = new Model_Tables_Spectrumtype();
    	$this->_modelDictionaryitems = new Model_Tables_Dictionaryitems();
    	$this->_modelCompoundsreference = new Model_Tables_Compoundreference();
    	$this->_modelCompoundsave = new Model_Tables_Compoundsave();
    	$this->_modelCompoundsalt = new Model_Tables_Compoundsalt();
    	$this->_modelCompoundsolvent = new Model_Tables_Compoundsolvent();
    	$this->_modelCompoundgain = new Model_Tables_Compoundgain();
    	$this->_modelSalt = new Model_Tables_Salt();
    	$this->_modelStatus = new Model_Tables_Status();
    	$this->_modelCompoundjson = new Model_Tables_Compoundjson();
    }
    public function jAction(){
    	$id = $this->_getParam('id');
    	$request = $this->getRequest(); 
    	$info = $this->_modelCompoundjson->getInfo($id);
    	$json = $info["json"];
    	$levelname=json_decode($json)->levelname;
    	$levelname=str_replace("\r\n", "####", $levelname);
    	//print_r(json_decode($json)->levelname);
    	//exit;
    	if ($request->isPost())
    	{
    		$params =$request->getPost();
    		$json = json_encode($params);
    		$newparams = array("json"=>$json,"id"=>$id);
    		
    		$this->_modelCompoundjson->modify($newparams, $id);
    		exit;
    		//$this->_redirect("/compound/index/");
    	}else{
    		//$info = $this->_modelCompoundjson->getInfo($id);
    		//$json = $info["json"];
    		//$levelname = json_decode($json)["levelname"];
    		include $this->_dzTemplate->getFile( 'j.html' );
    	}
    }
    public function jjAction(){
    	$id = $this->_getParam('id');
    	$request = $this->getRequest();
    	$params =$request->getPost();
    	$s = $params['s'];
    	$b = new Babel();
    	
    	//$s = $_REQUEST['s'];
    	$a = explode(">>",$s);
    	$infos = array();
    	$rideov = array("1"=>"限定");
    	foreach($a as $k=>$item){
    		$arritem=explode(".",$item);
			$newarritem = array();
    		foreach($arritem as $k1=>$subitem){
    			$subr = $b->smile_to_prop($subitem);
    			$subr["a"] = "a_".$k."_".$k1;
    			$subr["b"] = "b_".$k."_".$k1;
    			$subr["c"] = "c_".$k."_".$k1;
    			$subr["d"] = "d_".$k."_".$k1;
    			$subr["e"] = "e_".$k."_".$k1;
    			$subr["f"] = "f_".$k."_".$k1;
    			$subr["g"] = "g_".$k."_".$k1;
    			$newarritem[] = $subr;
    		}
    		$infos[] = $newarritem;
    	}
    	if($s == ""){
    		$info = $this->_modelCompoundjson->getInfo($id);
    		$json = $info["json"];
    	}
    	//$json = '{"levelname":"C1=CC=CC=C1.C1=CC=CC=C1>>C1=CC=CC=C1","a_0_0":"1","b_0_0":"1","c_0_0":"","d_0_0":"","e_0_0":"","f_0_0":"1","a_0_1":"2","b_0_1":"","c_0_1":"","d_0_1":"","e_0_1":"","f_0_1":"2","g":"1","a_1_0":"2","b_1_0":"","c_1_0":"","d_1_0":"","e_1_0":"","f_1_0":"2"}';
    	//print_r($infos);
    	include $this->_dzTemplate->getFile( 'jj.html' );
    	//$json = json_encode($infos);
    	//echo $json;
    }
    public function testAction(){
    	//$r = implode(",",$this->getProcessList());
    	//$statusList = $this->_modelStatus->getStatusList(1,implode(",",$this->getProcessList()));
    	//print_r($this->_modelStatus->getStatusList(1,implode(",",$this->getProcessList())));
    	//$r = $this->_modelProject->getProjectListByMember($this->_userinfo["userid"]);
    	$r = $this->_processlist;
    	print_r($r);
    	//echo $this->_userinfo;
    	echo "a";
    }
    /**
    * 获取化合物列表
    * @return unknown_type
    */
    public function indexAction()
    {
    	/*$options = $GLOBALS['application']->getOptions();
    	$numPerPage = $options["pagecount"];//每页显示的条数
        $ItemCount =  $this->_modelCompound->getCount();
        $PageCount = ceil($ItemCount/$numPerPage);
        $PageCount = $PageCount ? $PageCount : 1;*/
    	$styles = array("1"=>"基本信息","2"=>"合成路线");
    	$projectlist = $this->_modelProject->getProjectListByMember($this->_userinfo["userid"]);
    	$projectid = $this->_getParam('projectid');
    	if(!$projectid)$projectid = "-1";
		include $this->_dzTemplate->getFile( 'compound.manage.html' );
    }
    /**
     * 审核
     * */
    public function indexcheckAction()
    {
    	/*$options = $GLOBALS['applic ation']->getOptions();
    	 $numPerPage = $options["pagecount"];//每页显示的条数
    	$ItemCount =  $this->_modelCompound->getCount();
    	$PageCount = ceil($ItemCount/$numPerPage);
    	$PageCount = $PageCount ? $PageCount : 1;*/
    	$projectlist = $this->_modelProject->getProjectListByMember($this->_userinfo["userid"]);
    	$projectid = $this->_getParam('projectid');
    	if(!$projectid)$projectid = "-1";
    	include $this->_dzTemplate->getFile( 'compound.check.manage.html' );
    }
    public function advsearchAction(){
    	$stype=array(3=>"精确检索",1=>"子结构检索",2=>"相似度检索");
    	include $this->_dzTemplate->getFile( 'compound.advsearch.html' );
    }
    /**
    * 获取化合物列表
    * @return unknown_type
    */
    public function indexajaxAction()
    {
    	$projectid = $this->_getParam('projectid');
    	$status = $this->_getParam('status');
    	$style = $this->_getParam('style');
    	if(!$projectid)$projectid = "-2";
    	if(!$status)$status = "-2";
    	$projectlist = $this->_modelProject->getProjectListByMember($this->_userinfo["userid"]);
    	if(!$projectid||$projectid<1){
    		foreach($projectlist as $k=>$v){
    			$projectid.=$k.",";
    		}
    		$projectid.="-1";
    	}
    	if(!$projectid)$projectid = "-1";
    	syslog(LOG_INFO, "searchtest==1=".time());
        $options = $GLOBALS['application']->getOptions();
    	$numPerPage = $options["pagecount"];//每页显示的条数
        $page = intval($this->_getParam('page'));//默认页码
        $page = empty($page)?'1':$page;
   		//$s = $this->_getParam('s'); 
   		$json = $_POST['s'];
   		$r=$this->j2Array($json);
   		$r["projectid"] = $projectid;
   		$r["status"] = $status;
   		//print_r($r); exit;
   		$this->_session->searcharray = $r;//保存搜索条件
        $ItemCount =  $this->_modelCompound->getCount($r);
        syslog(LOG_INFO, "searchtest==2=".time());
        $PageCount = ceil($ItemCount/$numPerPage);
        //$projectlist = $this->_modelProject->getProjectList();
        //$projectlist = $this->_modelProject->getProjectListByMember($this->_userinfo["userid"]);
        if($page>$PageCount)$page=$PageCount;
        //echo  $this->_modelCompound->getIDList($r);exit;
        $infos0 = $this->_modelCompound->getList( $page, $numPerPage, $r );
        syslog(LOG_INFO, "searchtest==3=".time());
        foreach($infos0 as $info){
        	$info["projectid"] = $projectlist[$info["projectid"]];
        	$infos[] = $info;
        }
        //print_r($infos);exit;
        $random = rand(0, 100000);
        if($style=="1")
        	include $this->_dzTemplate->getFile( 'ajax/compound.manage.ajax.html' );
        elseif($style="2")
        	include $this->_dzTemplate->getFile( 'ajax/compound.manage.ajax.1.html' );
        syslog(LOG_INFO, "searchtest==4=".time());
    }
    public function indexcheckajaxAction()
    {
    	$projectid = $this->_getParam('projectid');
    	$status = $this->_getParam('status');
    	if(!$projectid)$projectid = "-2";
    	if(!$status)$status = "-2";
    	syslog(LOG_INFO, "searchtest==1=".time());
    	$options = $GLOBALS['application']->getOptions();
    	$numPerPage = $options["pagecount"];//每页显示的条数
    	$page = intval($this->_getParam('page'));//默认页码
    	$page = empty($page)?'1':$page;
    	//$s = $this->_getParam('s');
    	$json = $_POST['s'];
    	$r=$this->j2Array($json);
    	$r["projectid"] = $projectid;
    	$r["status"] = $status;
    	//print_r($r); exit;
    	$this->_session->searcharray = $r;//保存搜索条件
    	$ItemCount =  $this->_modelCompound->getCount($r);
    	syslog(LOG_INFO, "searchtest==2=".time());
    	$PageCount = ceil($ItemCount/$numPerPage);
    	$projectlist = $this->_modelProject->getProjectList();
    	if($page>$PageCount)$page=$PageCount;
    	//echo  $this->_modelCompound->getIDList($r);exit;
    	$infos0 = $this->_modelCompound->getList( $page, $numPerPage, $r );
    	syslog(LOG_INFO, "searchtest==3=".time());
    	foreach($infos0 as $info){
    		$info["projectid"] = $projectlist[$info["projectid"]];
    		$infos[] = $info;
    	}
    	//print_r($infos);exit;
    	$random = rand(0, 100000);
    	include $this->_dzTemplate->getFile( 'ajax/compound.check.manage.ajax.html' );
    	syslog(LOG_INFO, "searchtest==4=".time());
    }
    public function checkstatusajaxAction(){
    	$projectid = $this->_getParam('projectid');
    	$projectinfo = $this->_modelProject->getInfo($projectid);
    	$statuslist = $this->_modelStatus->getStatusListByuid($projectinfo["workflow"],$this->_userinfo["userid"]);
    	if(count($statuslist)<1)$statuslist=array("-2"=>"待审");
    	include $this->_dzTemplate->getFile( 'ajax/compound.check.status.manage.ajax.html' );
    }
    
    public function editstatusajaxAction(){
    	$projectid = $this->_getParam('projectid');
    	$projectinfo = $this->_modelProject->getInfo($projectid);
    	$statuslist = $this->_modelStatus->getStatusListByuid($projectinfo["workflow"],$this->_userinfo["userid"],false);
    	if(count($statuslist)<1)$statuslist=array("-2"=>"待审");
    	include $this->_dzTemplate->getFile( 'ajax/compound.check.status.manage.ajax.html' );
    }
    /**
    * 添加化合物
    * @return unknown_type
    */
    public function addAction()
    {
    	//print_r($this->_userinfo);exit;
    	$request = $this->getRequest();        
    	//$projectlist = $this->_modelProject->getProjectList();
    	$projectlist = $this->_modelProject->getProjectListByMember($this->_userinfo["userid"]);
    	//$spectrumtyps = $this->_modelSpectrumtype->getTypeList();
    	$spectrumtyps = $this->_modelDictionaryitems->getDictionary(6);
    	$solventlist = $this->_modelDictionaryitems->getDictionary(5);
    	$saltlist = $this->_modelSalt->getSaltList();
    	$patentlist = array(0=>"否",1=>"是",2=>"未知");
    	$button="false";
		$compoundno = $this->_configs["corporation"]. $this->_modelCompound->getnewid();
		$statusList = $this->_modelStatus->getStatusList(-1,implode(",",$this->getProcessList()),true);
        if ($request->isPost())
        {
            $params =$request->getPost();
            $ids=$this->_modelCompound->add($params,$this->_userinfo); 
            $id = $ids[0];
            $exist = $ids[1];
            $this->_redirect("/compound/modify/id/$id/exist/$exist");
            //$this->_redirect("/compound/index/");
        }
        include $this->_dzTemplate->getFile( 'compound.add.html' );
        
    }
    /**
    * 修改化合物
    * @return unknown_type
    */
    public function modifyAction()
    {
    	//print_r($_SERVER);exit;
    	$id = $this->_getParam('id');
    	$exist = $this->_getParam('exist');
    	if(!$exist)$exist = -1;
    		
    	//if($exist)
    		//echo "<script>alert('该化合物已经存在，请直接增加批次')</script>";
    	//$projectlist = $this->_modelProject->getProjectList();
    	$projectlist = $this->_modelProject->getProjectListByMember($this->_userinfo["userid"]);
    	$patentlist = array(0=>"否",1=>"是",2=>"未知");
    	//$spectrumtyps = $this->_modelSpectrumtype->getTypeList();
    	//$spectrumtyps = $this->_modelDictionaryitems->getDictionary(6);
    	$solventlist = $this->_modelDictionaryitems->getDictionary(5);
    	$saltlist = $this->_modelSalt->getSaltList();
    	$projectlist = $this->_modelProject->getProjectList();
    	$info = $this->_modelCompound->getInfo($id); 
    	$referencesinfos = $this->_modelCompoundsreference->getList(0,100,"",$id);
    	//$saveinfos = $this->_modelCompoundsave->getList(0,100,"",$id);
    	//$spectruminfos = $this->_modelCompoundspectrum->getList(0,100,"",$id);
    	$projectinfo = $this->_modelProject->getInfo($info["projectid"]); 
    	$statusList = $this->_modelStatus->getStatusList($projectinfo["workflow"],implode(",",$this->getProcessList()),true);
        $request = $this->getRequest();  
        $button="false";
        if ($request->isPost())
        {
        	$request =$request->getPost();   
        	//print_r($request);    exit; 	
            if (true)//服务端检查输入参数
            {
                $this->_modelCompound->modify($request,$id,$info["docfile"]);
                //$button="true";
                $this->_redirect("/compound/modify/id/$id/".$request["url"]);
            }
        } 
        include $this->_dzTemplate->getFile( 'compound.edit.html' );
    }
    public function showAction(){
    	$id = $this->_getParam('id');
    	$projectlist = $this->_modelProject->getProjectList();
    	$patentlist = array(0=>"否",1=>"是",2=>"未知");
    	//$spectrumtyps = $this->_modelSpectrumtype->getTypeList();
    	$spectrumtyps = $this->_modelDictionaryitems->getDictionary(6);
    	$solventlist = $this->_modelDictionaryitems->getDictionary(5);
    	$dict1 = $this->_modelDictionaryitems->getDictionary(1);
    	$saltlist = $this->_modelSalt->getSaltList();
    	$projectlist = $this->_modelProject->getProjectList();
    	$info = $this->_modelCompound->getInfo($id);
    	$info["solvent"] = $solventlist[$info["solvent"]];
    	$info["projectid"] = $projectlist[$info["projectid"]];
    	$info["salt"] = $saltlist[$info["salt"]];    	
    	$referencesinfos = $this->_modelCompoundsreference->getList(0,100,"",$id);
    	$gaininfos = $this->_modelCompoundgain->getList(0,100,"",$id);
    	$saveinfos0 = $this->_modelCompoundsave->getList(0,100,"",$id);
    	$spectruminfos0 = $this->_modelCompoundspectrum->getList(0,100,"",$id);
    	$saltInfos0 = $this->_modelCompoundsalt->getList(0,100,"",$id);
    	$solventInfos0 = $this->_modelCompoundsolvent->getList(0,100,"",$id);
    	
    	//$saltInfos = $this->_mod
    	foreach($spectruminfos0 as $item){
    		$item[spectrumtypeid] = $spectrumtyps[$item[spectrumtypeid]];
    		$spectruminfos[] = $item;
    	}
    	foreach($saveinfos0 as $item){
    		$item[dict1] = $dict1[$item[dict1]];
    		$saveinfos[] = $item;
    	}
    	foreach($saltInfos0 as $item){
    		$item[salt] = $saltlist[$item[salt]];
    		$saltinfos[] = $item;
    	}
    	foreach($solventInfos0 as $item){
    		$item[dict5] = $solventlist[$item[dict5]];
    		$solventInfos[] = $item;
    	}
    	//print_r($solventInfos);exit;
    	/*
    	$id = $this->_getParam('id');
    	$projectlist = $this->_modelProject->getProjectList();
    	$info = $this->_modelCompound->getInfo($id); 
    	$info["projectid"] = $projectlist[$info["projectid"]];*/
        include $this->_dzTemplate->getFile( 'compound.show.html' );
    }
    public function checkshowAction(){
    	$id = $this->_getParam('id');
    	$projectlist = $this->_modelProject->getProjectList();
    	$patentlist = array(0=>"否",1=>"是",2=>"未知");
    	//$spectrumtyps = $this->_modelSpectrumtype->getTypeList();
    	$spectrumtyps = $this->_modelDictionaryitems->getDictionary(6);
    	$solventlist = $this->_modelDictionaryitems->getDictionary(5);
    	$dict1 = $this->_modelDictionaryitems->getDictionary(1);
    	$saltlist = $this->_modelSalt->getSaltList();
    	$projectlist = $this->_modelProject->getProjectList();
    	$info = $this->_modelCompound->getInfo($id);
    	$projectinfo = $this->_modelProject->getInfo($info["projectid"]);
    	$info["solvent"] = $solventlist[$info["solvent"]];
    	$info["projectid"] = $projectlist[$info["projectid"]];
    	$info["salt"] = $saltlist[$info["salt"]];
    	$referencesinfos = $this->_modelCompoundsreference->getList(0,100,"",$id);
    	$gaininfos = $this->_modelCompoundgain->getList(0,100,"",$id);
    	$saveinfos0 = $this->_modelCompoundsave->getList(0,100,"",$id);
    	$spectruminfos0 = $this->_modelCompoundspectrum->getList(0,100,"",$id);
    	$saltInfos0 = $this->_modelCompoundsalt->getList(0,100,"",$id);
    	$solventInfos0 = $this->_modelCompoundsolvent->getList(0,100,"",$id);
    	$statusList = $this->_modelStatus->getStatusList($projectinfo["workflow"],implode(",",$this->getProcessList()));
    	
    	//$saltInfos = $this->_mod
    	foreach($spectruminfos0 as $item){
    		$item[spectrumtypeid] = $spectrumtyps[$item[spectrumtypeid]];
    		$spectruminfos[] = $item;
    	}
    	foreach($saveinfos0 as $item){
    		$item[dict1] = $dict1[$item[dict1]];
    		$saveinfos[] = $item;
    	}
    	foreach($saltInfos0 as $item){
    		$item[salt] = $saltlist[$item[salt]];
    		$saltinfos[] = $item;
    	}
    	foreach($solventInfos0 as $item){
    		$item[dict5] = $solventlist[$item[dict5]];
    		$solventInfos[] = $item;
    	}
    	include $this->_dzTemplate->getFile( 'compound.check.show.html' );
    }
    /**
    * 无刷新修改化合物
    * @return unknown_type
    */    
    public function modifyajaxAction()
    {
        $request = $this->getRequest();
        $params = $request->getPost();
        $arr = split("\|", $params['id']);
        $field = $arr[0];
        $id = $arr[1];
        $value = stripslashes($params['value']);
        $this->_modelCompound->modifyAjax($id,$field,$value);
        echo $value;
        exit;
    }
    public function modifyajaxreversAction()
    {
    	$field = $this->_getParam('field');
    	$pri = $this->_getParam('pri');
        $this->_modelCompound->modifyAjaxRevers($field,$pri);
        exit;
    }
    /**
    * 删除化合物
    */
    public function deleteAction()
    {
        $id = $this->_getParam('id');   
        $this->_modelCompound->del($id); 
        exit;
    }
    public function j2array($j){
    	$json=str_replace("\\", "", $j);
    	$a = json_decode($json);
    	$r = array();
    	foreach($a as $item){
    		$r[$item->name]=$item->value;
    	}
    	return $r;
    }
    public function toexcelbyidAction(){
    	$id = $this->_getParam('id');
    	$r = array();
    	$r["id"] = $id;
    	$this->toexcel($r);
    }
    public function toexcelallAction(){
    	$r = $this->_session->searcharray;
    	$this->toexcel($r);
    }
    private function toexcel($r)
    {
//     	$id = $this->_getParam('id');
//     	$r = array();
//     	$r["id"] = $id; 
    	header('Content-Type: application/vnd.ms-excel');
    	header('Content-Disposition: attachment;filename="smartchem.csv"');
    	header('Cache-Control: max-age=0');
    	$stmt = $this->_modelCompound->getList(1,15000,$r);
    	// 打开PHP文件句柄，php://output 表示直接输出到浏览器
    	$fp = fopen('php://output', 'a');
    	// 输出Excel列名信息
    	$head = array('编号', 'SMILE', 'CAS No.', '内部编号', '中文名', '英文名', '项目编号', "创建人", "创建时间", "修改时间");
    	foreach ($head as $i => $v) {
    		// CSV的Excel支持GBK编码，一定要转换，否则乱码
    		$head[$i] = iconv('utf-8', 'gbk', $v);
    	}    	
    	// 将数据通过fputcsv写到文件句柄
    	fputcsv($fp, $head);
    	// 计数器
    	$cnt = 0;
    	// 每隔$limit行，刷新一下输出buffer，不要太大，也不要太小
    	$limit = 100000;
    	// 逐行取出数据，不浪费内存
    	foreach($stmt as $row){
    		$cnt ++;
    		if ($limit == $cnt) { //刷新一下输出buffer，防止由于数据过多造成问题
    			ob_flush();
    			flush();
    			$cnt = 0;
    		}
    		$r = array($row["id"],$row["smile"],$row["casno"],$row["compoundno"],iconv('utf-8', 'gbk',$row["compoundname"]),$row["compoundnameen"],$row["projectid"],$row["username"],$row["addtime"],$row["modtime"]);
    		fputcsv($fp, $r);
    	}
    }
    public function tosdfbyidAction(){
    	$id = $this->_getParam('id');
    	$r = array();
    	$r["id"] = $id;
    	$this->tosdf($r);
    }
    public function tosdfallAction(){
    	$r = $this->_session->searcharray;
    	$this->tosdf($r);
    }
    private function tosdf($r)
    {
//     	$id = $this->_getParam('id');
//     	$r = array();
//     	$r["id"] = $id;
    	header('Content-Type: application/cd;charset=utf8');
    	header('Content-Disposition: attachment;filename="smartchem.sdf"');
    	header('Cache-Control: max-age=0');
    	$stmt = $this->_modelCompound->getList(1,10000,$r);
    	
//     	$key = md5(serialize($r));
//     	echo "aaa".$key;exit;
    	//print_r($stmt);
    	// 打开PHP文件句柄，php://output 表示直接输出到浏览器
    	$fp = fopen('php://output', 'a');
    	$cnt = 0;
    	// 每隔$limit行，刷新一下输出buffer，不要太大，也不要太小
    	$limit = 10000;
    	// 逐行取出数据，不浪费内存
    	foreach($stmt as $row){
    		$cnt ++;
    		if ($limit == $cnt) { //刷新一下输出buffer，防止由于数据过多造成问题
    			ob_flush();
    			flush();
    			$cnt = 0;
    		}
    		$sdf = str_replace("{#n#}", "\r\n", $row["mol"]);
    		$sdf = $row["id"].$sdf;
    		$sdf .= ">  <ID>\r\n".$row["id"]."\r\n";
    		$sdf .= "\r\n>  <SMILES>\r\n".$row["smile"]."\r\n";
    		$sdf .= "\r\n>  <CASNO>\r\n".$row["casno"]."\r\n";
    		$sdf .= "\r\n>  <CNNAME>\r\n".$row["compoundname"]."\r\n";
    		$sdf .= "\r\n>  <ENNAME>\r\n".$row["compoundnameen"]."\r\n";
    		$sdf .= "\r\n>  <FORMULA>\r\n".$row["formula"]."\r\n";
    		$sdf .= "\r\n>  <MOLECULARWEIGHT>\r\n".$row["molecularweight"]."\r\n";
    		$sdf .= "\r\n$$$$\r\n";
    		fputs($fp,$sdf);
    	}
    }
    public function checknoAction(){
    	$id = $this->_getParam('id');
    	if(!$id)$id=-1;
    	$compoundno = $this->_getParam('compoundno');
    	$r = $this->_modelCompound->checkno($compoundno,$id);
    	echo $r;
    }
    public function getidbynoAction(){
    	$no = $this->_getParam('no');
    	$resul = $this->_modelCompound->getInfoBycompoundno($no);
    	echo $resul["id"].",".$resul["projectid"];
    }
    public function checkhistoryAction(){
    	$modelReason = new Model_Tables_Reasons();
    	$id = $this->_getParam('id');
    	$infos = $modelReason->getList(1,100,$id);
    	include $this->_dzTemplate->getFile( 'ajax/reason.manage.ajax.html' );
    	//print_r($result);
    	//exit;
    }
    public function reasonAction(){
    	$request = $this->getRequest();
    	if ($request->isPost())
    	{
    		$post = $request->getPost();
    		$compoundid = $post["compoundid"];
    		$status = $post["status"];
    		$reason = $post["reason"];
    		$operator = $this->_userinfo["userid"];
    		$this->_modelCompound->updatestatus($compoundid, $status, $reason, $operator);
    		//print_r($request->getPost());
    		echo "<script>opener.PageClick(1);window.close();</script>";
    	}
    }
    public function chart1Action(){
    	//echo "a";exit;
    	include $this->_dzTemplate->getFile( 'charts/chart1.html' );
    }
}